﻿package mortal.game.view.copy.groupCopy.view.vipCopy
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.net.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.copy.*;
    import mortal.mvc.core.*;

    public class VipCopyRightInfoWin extends CopyInfoPanelBase
    {
        private var _bgImg:GImageBitmap;
        private var _bossAvatar:GImageBitmap;
        private var _copyName:GTextFiled;
        private var _bossName:GTextFiled;
        private var _bossLife:BaseProgressBar;
        private var _autoFightBtn:GLoadingButton;
        private var _leaveCopyBtn:GLoadingButton;
        private var _itemList:Vector.<BaseItem>;
        private var _entityInfo:EntityInfo;
        private var _tcopy:TCopy;
        private static var _instance:VipCopyRightInfoWin;

        public function VipCopyRightInfoWin(param1:String = "", param2:int = 250)
        {
            this._itemList = new Vector.<BaseItem>;
            super(ImagesConst.copyInfoPanelTitle_vipCopy, 262, 381, 10);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bgImg = UIFactory.gImageBitmap(ImagesConst.VipCopyRightInfoWinBg, 0, -5, _bodySprite);
            this._bossAvatar = UIFactory.gImageBitmap("", 103, 83, _bodySprite);
            var _loc_1:* = GlobalStyle.textFormatHuang2;
            _loc_1.size = 13;
            this._copyName = UIFactory.gTextField("", 100, 148, 100, 25, _bodySprite, _loc_1);
            this._bossName = UIFactory.gTextField("", 100, 172, 100, 25, _bodySprite, _loc_1);
            this._bossLife = UICompomentPool.getUICompoment(BaseProgressBar);
            this._bossLife.x = 100;
            this._bossLife.y = 205;
            this._bossLife.setBg(ImagesConst.PetLifeBg, true, 150, 12);
            this._bossLife.setProgress(ImagesConst.PetLife, true, 1, 1, 148, 10);
            this._bossLife.setLabel(BaseProgressBar.ProgressBarTextPercent, 0, -5, 150, 8);
            _bodySprite.addChild(this._bossLife);
            this._autoFightBtn = UIFactory.gLoadingButton(ResFileConst.autoFightBtn, 20, 305, 103, 38, _bodySprite);
            this._autoFightBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._leaveCopyBtn = UIFactory.gLoadingButton(ResFileConst.leaveCopyBtn, 140, 305, 103, 38, _bodySprite);
            this._leaveCopyBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bgImg.dispose(param1);
            this._bgImg = null;
            this._bossAvatar.dispose(param1);
            this._bossAvatar = null;
            this._copyName.dispose(param1);
            this._copyName = null;
            this._bossName.dispose(param1);
            this._bossName = null;
            this._bossLife.dispose(param1);
            this._bossLife = null;
            this._autoFightBtn.dispose(param1);
            this._autoFightBtn = null;
            this._leaveCopyBtn.dispose(param1);
            this._leaveCopyBtn = null;
            if (this._entityInfo)
            {
                this._entityInfo.removeEventListener(EntityInfoEventName.UpdateLife, this.updateLife);
                this._entityInfo.removeEventListener(EntityInfoEventName.DisposeEntity, this.removeEntity);
                this._entityInfo = null;
            }
            this._tcopy = null;
            this._itemList.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            if (event.target == this._leaveCopyBtn)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyClickQuickBtn));
            }
            else if (event.target == this._autoFightBtn)
            {
                AIManager.cancelAll();
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoFight_A));
            }
            return;
        }// end function

        public function set tcopy(param1:TCopy) : void
        {
            this._tcopy = param1;
            this._copyName.text = this._tcopy.name;
            CallLater.setCallLater(this.getBoss, 2);
            this.createItemList();
            return;
        }// end function

        private function getBoss(param1:Object) : void
        {
            var _loc_4:TBoss = null;
            var _loc_2:* = Cache.instance.entity.getAllEntityInfo(EEntityType._EEntityTypeBoss);
            var _loc_3:* = _loc_2[0] as EntityInfo;
            if (_loc_3)
            {
                _loc_4 = BossConfig.instance.getInfoByCode(_loc_3.entityInfo.code);
                if (_loc_4 && _loc_4.category == EBossCategory._EBossCategoryBoss)
                {
                    this._entityInfo = _loc_3;
                    this._bossName.text = _loc_4.name;
                    this._bossAvatar.imgUrl = _loc_4.avatarId + ".png";
                    this._entityInfo.addEventListener(EntityInfoEventName.UpdateLife, this.updateLife);
                    this._entityInfo.addEventListener(EntityInfoEventName.DisposeEntity, this.removeEntity);
                    this.updateLife();
                }
            }
            return;
        }// end function

        private function updateLife(event:Event = null) : void
        {
            this._bossLife.setValue(this._entityInfo.entityInfo.life, this._entityInfo.entityInfo.maxLife);
            return;
        }// end function

        private function removeEntity(event:Event) : void
        {
            if (this._entityInfo)
            {
                this._entityInfo.removeEventListener(EntityInfoEventName.UpdateLife, this.updateLife);
                this._entityInfo.removeEventListener(EntityInfoEventName.DisposeEntity, this.removeEntity);
                this._entityInfo = null;
            }
            return;
        }// end function

        private function createItemList() : void
        {
            var _loc_2:BaseItem = null;
            var _loc_3:int = 0;
            if (this._itemList.length)
            {
                return;
            }
            var _loc_1:* = this._tcopy.rewardShow.split("#");
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_2 = UICompomentPool.getUICompoment(BaseItem);
                _loc_2.setItemStyle(ItemStyleConst.Small, ImagesConst.PetItemBg, 4, 4);
                _loc_2.x = 60 + _loc_3 * 48;
                _loc_2.y = 243;
                _loc_2.isShowLock = true;
                var _loc_4:Boolean = false;
                _loc_2.isDropAble = false;
                _loc_2.isDragAble = _loc_4;
                _bodySprite.addChild(_loc_2);
                _loc_2.itemData = new ItemData(int(_loc_1[_loc_3]));
                this._itemList.push(_loc_2);
                this.pushUIToDisposeVec(_loc_2);
                _loc_3++;
            }
            return;
        }// end function

        public static function get instance() : VipCopyRightInfoWin
        {
            if (_instance == null)
            {
                _instance = new VipCopyRightInfoWin;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
